//
//  BCAppDelegate.m
//  GSBlockChain
//
//  Created by guoshikeji_a on 2018/11/12.
//  Copyright © 2018年 guoshikeji. All rights reserved.
//

#import "BCAppDelegate.h"

//category
#import "BCAppDelegate+AppearanceSet.h"

/**
 mian VCs
 */
#import "MainTabBarController.h"

//
#import "BCLabguageSettingManager.h"
//aliyunOSS
#import "AliyunOSSManager.h"
//APNS register
#import "AKRemoteNotificationHelper.h"

@interface BCAppDelegate () <UNUserNotificationCenterDelegate>

@end

@implementation BCAppDelegate

#pragma mark - getter window
 //初始化window视图
- (BCMainWindow *)window {
    if (!_window) {
        _window = [[BCMainWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    }
    return _window;
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    [NSThread sleepForTimeInterval:2];
    //appearceSet
    [self bc_customAppearanceSet];
    //
    [self launchManagers];
    //进入界面
    [self toMainAction];
    
    //申请注册APNs
    [self replyPushNotificationAuthorization:application];
    //
    return YES;
}

/**
 进入主界面
 */
- (void)toMainAction {
    MainTabBarController *mainVC = [[MainTabBarController alloc] init];
    self.window.rootViewController = mainVC;
    [self.window makeKeyAndVisible];
}

/**
 启动和配置一些managers
 */
- (void)launchManagers {
     NSLog(@"%@",[GeneralParameterManager sharedGeneral].description);
    //启动网络监听管理器
    [[NetworkStatusMonitorManager sharedMonitor] startMonitoring];
    //language 语言配置
//    [BCLabguageSettingManager shared].appLanguage = BCLanguageTypeChineseTraditional;
    //配置aliyunOSS 请求一下配置数据
//    [AliyunOSSManager sharedOSS];
    
    //IQKey
    [IQKeyboardManager sharedManager].toolbarDoneBarButtonItemText = BCLocalizedKey(@"Done");
    [IQKeyboardManager sharedManager].shouldResignOnTouchOutside = true;
}

#pragma mark - 申请通知权限
// 申请通知权限
- (void)replyPushNotificationAuthorization:(UIApplication *)application{
#if TARGET_IPHONE_SIMULATOR
    NSLog(@"模拟器不支持APNs");
#else
    [AKRemoteNotificationHelper requestPushNotificationAuthorization:application delegate:self];
#endif
}
/*
 *  苹果推送注册成功回调，将苹果返回的deviceToken上传到CloudPush服务器s
 */
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
    
    //正确写法
    NSString *deviceString = [[deviceToken description] stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"<>"]];
    deviceString = [deviceString stringByReplacingOccurrencesOfString:@" " withString:@""];
    
    NSLog(@"deviceToken===========%@",deviceString);
}
/*
 *  苹果推送注册失败回调
 */
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
    NSLog(@"didFailToRegisterForRemoteNotificationsWithError %@", error);
}

#pragma mark - UNUserNotificationCenterDelegate


@end
